Summary#
In this section, we learned the essential parts of the Go language. This included handling errors, using Go concurrency, taking advantage of Go's testing framework, and an introduction to Go's newest feature, generics. The skills acquired in this section are essential for all future sections.
We should now possess the ability to read Go code contained in the rest of the book. In addition, this section has given us the necessary skills to write our own Go code. We’ll use these skills to manipulate files in the filesystem, execute commands on remote machines, and build RPC services that can do a myriad of tasks. We'll build chatbots in order to do chat-based operations (ChatOps) and write software to extend kubernetes. The learnings here are truly foundational.
Quiz#
What inputs wouldn’t yield an error in the following code?
func TestGreet(t *testing.T) {
name := "Sam"
want := "Hello Sam"
got, err := Greet(name)
if got != want || err != nil {
t.Fatalf("TestGreet(%s): got %q/%v, want %q/nil", name, got, err, want)
}
}
Sam
Hello Sam
Both A and B
Hello
Adding Type Parameters to Struct Types
Introduction